package com.foreknow.demo13;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ListDemo {
    public static void main(String[] args) {
        //1.创建一个List集合 <Integer>表示范型：用来约束集合当中元素的类型
        List<Integer> list = new ArrayList();
        List<Double> list1 = new ArrayList<>();
        //2.向集合中添加元素
        list.add(1);
        list.add(12);
        list.add(13);
        //3.从集合中获取元素
        Integer a = list.get(0);
        System.out.println(a);
        System.out.println("----");
        //4.遍历集合
        for (int i = 0;i<list.size();i++) {
            System.out.println(list.get(i));
        }

        System.out.println("--foreach--");
        for (Integer ii : list) {
            System.out.println(ii);
        }

        System.out.println("---迭代器Iterator<E>接口---");
        Iterator<Integer> it = list.iterator();
        while (it.hasNext()) {
            Integer ii = it.next();
            System.out.println(ii);
        }

    }
}
